<?php 

if ($section != "comments") {
	if (($action == "add") || (($action == "edit") && ($vid == "default"))) {
		$insertSQL = sprintf("INSERT INTO project_deliverable 
			(
			cid, 
			vid, 
			mid,
			del_num,
			pd_name, 
			pd_desc1, 
			pd_desc2, 
			pd_desc3, 
			pd_desc4, 
			pd_desc5
			) 
			VALUES 
			(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s)", 
				GetSQLValueString($cid, "int"),
				GetSQLValueString($_POST['vid'], "int"),
				GetSQLValueString($_POST['mid'], "int"),
				GetSQLValueString($_POST['del_num'], "int"),
				GetSQLValueString($_POST['pd_name'], "text"),
				GetSQLValueString($_POST['pd_desc1'], "text"),
				GetSQLValueString($_POST['pd_desc2'], "text"),
				GetSQLValueString($_POST['pd_desc3'], "text"),
				GetSQLValueString($_POST['pd_desc4'], "text"),
				GetSQLValueString($_POST['pd_desc5'], "text")
			);
  						
		mysql_select_db($database, $connection);
  		$result1 = mysql_query($insertSQL, $connection) or die(mysql_error());

		$query_id_check = sprintf("SELECT id FROM %s WHERE cid='%s' ORDER BY id DESC", $dbTable, $cid);
		$id_check = mysql_query($query_id_check, $connection) or die(mysql_error());
		$row_id_check = mysql_fetch_assoc($id_check);
		
			if ($go == "detail") $insertGoTo = "../index.php?section=view_proposal&dbTable=".$dbTable."&cid=".$cid."&vid=".$_POST['vid']."&id=".$row_id_check['id']."&msg=1&modal_window=".$modal_window;
			elseif ($go == "overview") $insertGoTo = "../index.php?section=view_proposal&cid=".$cid."&msg=1&modal_window=".$modal_window;
			elseif (($section == "proj_deliv") && ($go == "default")) $insertGoTo = "../index.php?section=proj_deliv&action=confirm&cid=".$cid."&vid=".$_POST['vid']."&id=".$row_id_check['id']."&msg=1&modal_window=".$modal_window;
			//elseif ($section == "admin") $insertGoTo = "../index.php?section=list&msg=2";
			else $insertGoTo = $insertGoTo."&msg=4&modal_window=".$modal_window;
			header(sprintf("Location: %s", $insertGoTo));
		}
		
		if (($action == "edit") && ($vid != "default")) { 
		$updateSQL = sprintf("UPDATE project_deliverable 
			SET 
			cid=%s, 
			vid=%s, 
			mid=%s, 
			del_num=%s,
			pd_name=%s, 
			pd_desc1=%s,
			pd_desc2=%s, 
			pd_desc3=%s, 
			pd_desc4=%s, 
			pd_desc5=%s 
			WHERE id=%s", 
				GetSQLValueString($cid, "int"),
				GetSQLValueString($vid, "int"),
				GetSQLValueString($_POST['mid'], "int"),
				GetSQLValueString($_POST['del_num'], "int"),
				GetSQLValueString($_POST['pd_name'], "text"),
				GetSQLValueString($_POST['pd_desc1'], "text"),
				GetSQLValueString($_POST['pd_desc2'], "text"),
				GetSQLValueString($_POST['pd_desc3'], "text"),
				GetSQLValueString($_POST['pd_desc4'], "text"),
				GetSQLValueString($_POST['pd_desc5'], "text"),
				GetSQLValueString($id, "int")
			);
  						
		mysql_select_db($database, $connection);
  		$result1 = mysql_query($updateSQL, $connection) or die(mysql_error());
		
		if (($section != "comments") && (($_POST['mid'] == "") || ($_POST['del_num'] == "") || ($_POST['pd_name'] == "") || ($_POST['pd_desc1'] == "") || ($_POST['pd_desc2'] == "") || ($_POST['pd_desc3'] == "") || ($_POST['pd_desc4'] == "") || ($_POST['pd_desc5'] == ""))) {
			header("location:../index.php?section=".$section."&action=edit&dbTable=".$dbTable."&cid=".$cid."&vid=".$vid."&id=".$id."&go=missing&msg=2&modal_window=".$modal_window); 
			}
		else  {
		
			if (($go == "no") || ($go == "missing")) $updateGoTo = "../index.php?section=proj_deliv&action=confirm&cid=".$cid."&vid=".$_POST['vid']."&id=".$id."&msg=1&modal_window=".$modal_window;
			elseif ($go == "review") $updateGoTo = "../index.php?section=proposal_reveiw&cid=".$cid."&msg=4&modal_window=".$modal_window;
			elseif ($go == "overview") $updateGoTo = "../index.php?section=view_proposal&cid=".$cid."&msg=2&modal_window=".$modal_window."#map";
			//else $updateGoTo = "../index.php?section=clo&action=view&cid=".$cid."&msg=1";
			//if ($section == "admin") $insertGoTo = "../index.php?section=list&msg=2";
			else $updateGoTo = $updateGoTo."&msg=5&modal_window=".$modal_window;
			header(sprintf("Location: %s", $updateGoTo));
			}
		}
	}

?>